﻿@using Volo.Abp.UI.Navigation

@{
    var elementId = MenuItem.MenuItem.ElementId ?? "MenuItem_" + MenuItem.MenuItem.Name.Replace(".", "_");
    var url = MenuItem.MenuItem.Url == null ? "#" : MenuItem.MenuItem.Url.TrimStart('/', '~');
}


@if (MenuItem.MenuItem.IsLeaf && MenuItem.MenuItem.Url != null)
{
    <MenuItem Key="@elementId" RouterLink="@url" Disabled="@MenuItem.MenuItem.IsDisabled">
        @if (!MenuItem.MenuItem.Icon.IsNullOrWhiteSpace())
        {
            <Icon Type="@MenuItem.MenuItem.Icon" Theme="outline"></Icon>
        }
        <span>@MenuItem.MenuItem.DisplayName</span>
    </MenuItem>
}
else
{
    <SubMenu Title="@MenuItem.MenuItem.DisplayName" TitleTemplate="@GetSubMenuTemplate(MenuItem.MenuItem)" Key="@elementId">
        @foreach (var childMenuItem in MenuItem.Items)
        {
            <MainMenuItem Menu="@Menu" MenuItem="@childMenuItem" />
        }
    </SubMenu>
}


@{

    RenderFragment GetSubMenuTemplate(ApplicationMenuItem menu)
    {
        return @<span>
        @if (!MenuItem.MenuItem.Icon.IsNullOrWhiteSpace())
                {
        <Icon Type="@MenuItem.MenuItem.Icon" Theme="outline"></Icon>
                }
        <span>@menu.DisplayName</span>
    </span>;
    }
}